<template>
  <el-form
      label-position="right"
      label-width="100px"
      :model="search"
      style="max-width: 100%">
    <div>患者信息查询</div>
    <el-form-item label="病历号">
      <el-input v-model="search.caseNumber" placeholder="请输入病历号"/>
    </el-form-item>
    <el-form-item label="患者名">
      <el-input v-model="search.realName" placeholder="请输入患者名"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSearch">搜索</el-button>
    </el-form-item>
  </el-form>

  <div>患者信息确认</div>
  <el-form
      label-position="right"
      label-width="100px"
      :model="search"
      style="max-width: 100%">
    <el-form-item label="患者名">
      <el-input v-model="searchRegisterResult.realName" disabled/>
    </el-form-item>
    <el-form-item label="身份证号">
      <el-input v-model="searchRegisterResult.cardNumber" disabled/>
    </el-form-item>
    <el-form-item label="年龄">
      <el-input v-model="searchRegisterResult.age" disabled/>
    </el-form-item>
    <el-form-item label="性别">
      <el-input v-model="searchRegisterResult.gender" disabled/>
    </el-form-item>
  </el-form>

  <el-button>项目金额: {{ projPrice }}</el-button>
  <el-button @click="balance">收费结算</el-button>

  <el-table :data="checkRequestList"
            ref="checkRequestTable"
            @selection-change="selectionChange"
  >
    <el-table-column type="selection"/>
    <el-table-column prop="tech.techName" label="项目名称"/>
    <el-table-column prop="tech.techPrice" label="单价"/>
    <el-table-column prop="tech.techType" label="类型"/>
    <el-table-column prop="tech.techFormat" label="规格"/>
    <el-table-column prop="count" label="数量"/>
    <el-table-column prop="creationTime" label="开立时间"/>
  </el-table>
</template>

<script>
import axios from 'axios'

export default {
  name: "ExpenseChargeView",
  data() {
    return {
      search: {
        caseNumber: '',
        realName: ''
      },
      searchRegisterResult: {
        realName: '',
        cardNumber: '',
        age: '',
        gender: ''
      },
      checkRequestList: [],
      projPrice: 0
    }
  },
  methods: {
    balance() {
      for (let row of this.$refs.checkRequestTable.getSelectionRows()) {
        row.checkState = '已缴费'
        axios({
          url: '/api/check_request/update',
          method: 'post',
          data: row
        }).then(res => {
        }).catch(err => {
        }).then(() => {
        })
      }
    },
    handleSearch() {
      this.searchRegisterResult.realName = ''
      this.searchRegisterResult.cardNumber = ''
      this.searchRegisterResult.age = ''
      this.searchRegisterResult.gender = ''
      axios({
        url: '/api/check_request/query',
        method: 'post',
        data: this.search
      }).then(res => {
        this.checkRequestList = res.data.data.filter(checkRequest => {
          return checkRequest.checkState == '已开立'
        })

        if (this.checkRequestList.length != 0) {
          this.searchRegisterResult = this.checkRequestList[0].register
        }
      }).catch(err => {
      }).then(() => {
      })
    },
    selectionChange(selection) {
      this.projPrice = 0
      for (let select of selection) {
        this.projPrice += parseFloat(select.tech.techPrice)
      }
    }
  }
}
</script>

<style scoped>

</style>